// SPDX-License-Identifier: GPL-3.0-or-later

import QtQuick
import QtQuick.Layouts
import QtQuick.Controls
import Fk
import Fk.Components.LunarLTK
import Fk.Pages.LunarLTK
import Fk.Components.Common

GraphicsBox {
  // property var options: []
  property var all_options: []
  property string skill_name: ""
  property int playergold

  id: root
  title.text: Lua.tr("$Choice").arg(Lua.tr(skill_name))
  width: Math.max(140, body.width + 20)
  height: body.height + title.height + 20

  GridLayout {
    id: body
    x: 10
    y: title.height + 5
    flow: GridLayout.TopToBottom
    rows: 8
    columnSpacing: 10

    Repeater {
      model: all_options

      MetroButton {
        Layout.fillWidth: true
        text: Lua.tr(modelData.name) + ":$" + modelData.cost
        enabled: playergold >= modelData.cost

        onClicked: {
          // console.log(index)
          const reply = 
            {
              pos: index+1,
              choices: modelData,
            }
          ;
          ClientInstance.replyToServer("", reply);
          close();
          roomScene.state = "notactive";
        }
      }
    }
  }

  function loadData(data) {
    // console.log(data)
    skill_name = data[0];
    // detail_content = data[1];
    all_options = data[1] ?? [];
    playergold = data[2]
  }
}
